unit EKdelete;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, IBQuery, IBSQL, ComCtrls, Db, Grids, DBGrids;

type
  TfmEKDelete = class(TForm)
    Label1: TLabel;
    edINW_N: TEdit;
    btnDelete: TButton;
    PageCtrl: TPageControl;
    TabSheet1: TTabSheet;
    DBGrid1: TDBGrid;
    DataSrc: TDataSource;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure edINW_NKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btnDeleteClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    FQuery: TIBQuery;
    procedure DisplayData;
  public
    { Public declarations }
  end;

var
  fmEKDelete: TfmEKDelete;

implementation
uses DicDM;

{$R *.DFM}

procedure TfmEKDelete.FormCreate(Sender: TObject);
begin
  FQuery := dmDic.qryBooks;
  DataSrc.DataSet := FQuery;
end;

procedure TfmEKDelete.FormShow(Sender: TObject);
begin
  edINW_N.SetFocus;
end;

procedure TfmEKDelete.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = 27 then Close;
end;

procedure TfmEKDelete.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FQuery.Close;
  Action := caFree;
end;

procedure TfmEKDelete.DisplayData;
begin
    FQuery.Close;
    FQuery.SQL.Clear;
    FQuery.SQL.Add('SELECT * FROM GET_AUTHOR_ZAGL_BY_ID_STR(:IN_ID_STR)');
    FQuery.ParamByName('IN_ID_STR').AsString := edINW_N.Text;
    FQuery.Open;
    if not FQuery.Eof then begin
      btnDelete.Enabled := True;
    end
    else begin
      btnDelete.Enabled := False;
    end;
end;

procedure TfmEKDelete.edINW_NKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = 13 then begin
    DisplayData;
  end;
end;

procedure TfmEKDelete.btnDeleteClick(Sender: TObject);
var q: TIBSQL;
  book_id: integer;
begin
  book_id := FQuery.FieldByName('BOOK_ID').AsInteger;
  q := dmDic.CreateIBSQL(Self);
  q.Transaction.StartTransaction;
  q.SQL.Text := 'DELETE FROM EK WHERE ID = :book_id';
  q.ParamByName('book_id').AsInteger := book_id;
  q.ExecQuery;
  q.Transaction.Commit;
  q.Free;
  //
  DisplayData;
end;

end.
